{% extends "base.html" %}
{% load i18n static wger_extras %}

{% block title %}{% translate "API key" %}{% endblock %}


{% block content %}
    <p>
        Please use JWT authentication if possible. More details in the
        <a href="https://wger.readthedocs.io/en/latest/">online documentation</a>.
    </p>

    <div class="card mb-4 {% if token %}text-white bg-success{% else %}bg-light{% endif %}">
        <div class="card-header">
            {% translate "Your API key" %}
        </div>
        <div class="card-body">
            {% if token %}
                <strong>{{ token.key }}</strong>
            {% else %}
                <em>{% translate "You have no API key yet" %}</em>
            {% endif %}
        </div>
    </div>

    <p>
        Pass "Token {% if token %}{{ token.key }}{% else %}1234567890abcde...{% endif %}" in the
        <code>Authorization</code> header to use it
    </p>

    <p>Example with curl:</p>
    <pre>
curl -X GET https://wger.de/api/v2/routine/ \
     -H 'Authorization: Token {% if token %}{{ token.key }}{% else %}1234567890abcde...{% endif %}'
</pre>

{% endblock %}


{% block sidebar %}
    <h4>{% translate "Options" %}</h4>

    <p>
        {% if token %}
            <a href="{% url 'core:user:api-key' %}?new_key=true"
               class="btn btn-block btn-light">{% translate 'Delete current API key and generate new one' %}</a>
        {% else %}
            <a href="{% url 'core:user:api-key' %}?new_key=true"
               class="btn btn-block btn-light">{% translate 'Generate new API key' %}</a>
        {% endif %}
    </p>

    <p>
        <a href="{% url 'software:api' %}"
           class="btn btn-block btn-light">{% translate 'Documentation' %}</a>
    </p>
{% endblock %}
